    
    
import os, subprocess
import shlex
import shutil
from global_config import *

cmd = 'pyinstaller http_server.py -y'
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while p.poll() is None:
    line = p.stdout.readline()
    line = line.strip()
    if line:
        print('[{}]'.format(line))
dstPath = './dist/http_server'

internalPath = os.path.join(dstPath,'_internal')
internalCkpPath = os.path.join(internalPath,'checkpoint')
ckpPath = os.path.join(dstPath,'checkpoint')

srcCkpPath = 'D:/DevelopProj/Yuji/Audio2Face/YAudio2BS/checkpoint'

model = ckp_rel
srcCkpBSModelPath = os.path.join(srcCkpPath,model)
dstCkpBSModelPath = os.path.join(internalCkpPath,model)
os.makedirs(os.path.dirname(dstCkpBSModelPath),exist_ok=True)

shutil.copy(srcCkpBSModelPath,dstCkpBSModelPath)

if 'wav2vec_torch' in feature_type:
    srcCkpWav2VecPath = os.path.join(srcCkpPath,'et/jonatasgrosman/wav2vec2-large-xlsr-53-chinese-zh-cn')
    dstCkpWav2VecPath = os.path.join(ckpPath,'et/jonatasgrosman/wav2vec2-large-xlsr-53-chinese-zh-cn')
    
    os.makedirs(dstCkpWav2VecPath,exist_ok=True)
    if os.path.exists(dstCkpWav2VecPath):
        shutil.rmtree(dstCkpWav2VecPath)
    shutil.copytree(srcCkpWav2VecPath,dstCkpWav2VecPath)



envPath = 'D:/miniconda3/envs/pytorch_cpu/Lib/site-packages'

shutil.copytree(os.path.join(envPath,'audiolazy'),os.path.join(internalPath,'audiolazy'))


lpcDllPath = 'D:/DevelopProj/Yuji/Audio2Face/YAudio2BS/LPC.dll'
shutil.copy(lpcDllPath,internalPath)



